﻿using System;

namespace sinetd
{
    public class BaseManagerElement : MarshalByRefObject, IManagerElement
    {
        #region cstor

        public BaseManagerElement(string name)
        {
            this.name = name;
            this.id = this.Name + this.GetHashCode();

            cfg = new Config();
            ConfigDefault();
        }

        public BaseManagerElement(string name, string id)
        {
            this.name = name;
            this.id = id;

            cfg = new Config();
            ConfigDefault();
        }

        #endregion

        #region IManagerElement

        private string id = "";
        private string name = "";
        private string config = "";

        public string Id
        {
            get { return id; }
            internal set { id = value; }
        }

        public string Name
        {
            get { return name; }
        }

        public string Config
        {
            get { return config; }
            set
            {
                config = value;
                string[] l = config.Split(';');
                foreach (string ll in l)
                {
                    string[] p = ll.Split('=');
                    if (p.Length == 2)
                        cfg[p[0]] = p[1];
                }
                ConfigChanged();
            }
        }

        #endregion

        protected Config cfg;

        public virtual void ConfigChanged() { }

        public virtual void ConfigDefault() { }
    }
}
